﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Case.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div id="editform">     
    </div>
    <script type="text/javascript">
        $(function () { 
            $.get('<%=Url.Action(ViewBag.Case != null ? "edit" : "create") %>',
                  { <%=ViewBag.Case != null ? "id:'"+ViewBag.Case.Id.ToString()+"'" : "TypeId:'"+ViewBag.CaseTypeId.ToString()+"'"  %>},
            function(d){
                $('#editform').html(d);
                regf();
            });
        });

        function regf() {
            $('#editform form').ajaxForm({
                url: '<%=Url.Action(ViewBag.Case != null ? "edit":"create") %>',
                success: function (d) {
                    if (typeof d == 'object') {
                    tell('succes');
                    <% if(ViewBag.Case != null){%>
                        tell('datele dosarului au fost salvate cu success');
                    <%} else
                       {%>
                       tell('dosarul a fost creat cu success', '<%=Url.Action("details", new{}) %>/'+d.Id)
                       //setTimeout('window.location = \'<%=Url.Action("details", new{}) %>/'+d.Id+"'", 1500);
                       <%}%>                    
                    }
                    else {
                        $('#editform').html(d);
                        regf();
                    }
                }
            });
        }
    </script>
</asp:Content>
